package api.model;

import m.common.model.FieldMeta;
import m.common.model.TableMeta;
import m.common.model.type.FieldType;
import m.common.model.util.ModelQueryList;
import m.common.model.util.QueryCondition;
import m.system.cache.FlushCacheList;
import m.system.util.StringUtil;
import manage.model.StatusModel;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@TableMeta(name="ot_api_convert_data",description="转换数据表")
public class ApiConvertData extends StatusModel implements FlushCacheList {
    @FieldMeta(name="description",type= FieldType.STRING,notnull = true,length=200,description="描述")
    private String description;
    @FieldMeta(name="trigger_condition",type=FieldType.STRING,length=10,notnull = true,description="触发条件",dictOption = "A:自动触发,T:定时触发")
    private String triggerCondition;
    @FieldMeta(name="timer_condition",type=FieldType.STRING,length=10,notnull = true,description="插入条件",dictOption = "A:根据系统更新时间列插入或更新,B:全量插入或更新,C:全删后再全量插入")
    private String timerCondition;
    @FieldMeta(name="timer_long",type=FieldType.STRING,length=10,notnull = true,description="定时时长|分钟",dictOption = "1:1分钟,10:10分钟,60:1小时,360:6小时,1440:1天,4320:3天")
    private String timerLong;
    @FieldMeta(name="last_date",type=FieldType.DATE,description="最后执行时间")
    private Date lastDate;

    @FieldMeta(name="source_table",type= FieldType.STRING,length=50,notnull = true,description="原数据表")
    private String sourceTable;
    @FieldMeta(name="save_table",type= FieldType.STRING,length=50,notnull = true,description="保存表")
    private String saveTable;
    @FieldMeta(name="data_handler",type=FieldType.STRING,length=500,description="数据处理")
    private String[] dataHandler;

    public String getTimerCondition() {
        return timerCondition;
    }

    public void setTimerCondition(String timerCondition) {
        this.timerCondition = timerCondition;
    }

    public Date getLastDate() {
        return lastDate;
    }

    public void setLastDate(Date lastDate) {
        this.lastDate = lastDate;
    }

    public String[] getDataHandler() {
        return dataHandler;
    }

    public void setDataHandler(String[] dataHandler) {
        this.dataHandler = dataHandler;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getTriggerCondition() {
        return triggerCondition;
    }

    public void setTriggerCondition(String triggerCondition) {
        this.triggerCondition = triggerCondition;
    }

    public String getTimerLong() {
        return timerLong;
    }

    public void setTimerLong(String timerLong) {
        this.timerLong = timerLong;
    }

    public String getSourceTable() {
        return sourceTable;
    }

    public void setSourceTable(String sourceTable) {
        this.sourceTable = sourceTable;
    }

    public String getSaveTable() {
        return saveTable;
    }

    public void setSaveTable(String saveTable) {
        this.saveTable = saveTable;
    }

    @Override
    public List<ApiConvertData> getCacheList(String sourceTable) throws Exception {
        List<QueryCondition> ls=new ArrayList<>();
        ls.add(QueryCondition.eq("status","0"));
        if(StringUtil.notSpace(sourceTable)){
            ls.add(QueryCondition.eq("sourceTable",sourceTable));
        }
        return ModelQueryList.getModelList(ApiConvertData.class,new String[]{"*"},null,
                QueryCondition.and(ls.toArray(new QueryCondition[]{})));
    }
}
